//
//  MyLocationManager.m
//  iFoundIt
//
//  Created by Navid Shariat on 17/05/10.
//  Copyright 2010 QUT. All rights reserved.
//

#import "MyLocationManager.h"


@implementation MyLocationManager
@synthesize locationManager;

- (void)startUpdates{
	
    // Create the location manager if this object does not
    // already have one.
    if (nil == locationManager)
        locationManager = [[CLLocationManager alloc] init];

    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
	
    // Set a movement threshold for new events
	
    locationManager.distanceFilter = 500;
    [locationManager startUpdatingLocation];	
}

// Delegate method from the CLLocationManagerDelegate protocol.

- (void)locationManager:(CLLocationManager *)manager
			didUpdateToLocation:(CLLocation *)newLocation
			fromLocation:(CLLocation *)oldLocation
{
    // If it's a relatively recent event, turn off updates to save power
	
    NSDate* eventDate = newLocation.timestamp;
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
    if (abs(howRecent) < 5.0)
    {		
       [manager stopUpdatingLocation];
       printf("latitude %+.6f, longitude %+.6f\n",
	   newLocation.coordinate.latitude,
	   newLocation.coordinate.longitude);	
    }
    // else skip the event and process the next one.	
}
@end
